﻿namespace Pna.InfoSource.Sbb.JsonModels
{
    using System;
    using System.Globalization;

    using ServiceStack.ServiceHost;

    /// <summary>
    /// The request connection info.
    /// </summary>
    [Route("/connections")]
    public class RequestConnectionInfo : IReturn<ConnectionInfo>
    {
        public string From { get; set; }

        public string To { get; set; }

        public string[] Via { get; set; }

        /// <summary>
        /// Gets or sets the date for the connection in format YYYY-MM-DD.
        /// </summary>
        public string Date { get; set; }

        /// <summary>
        /// Gets or sets the time of the connection in format hh:mm.
        /// </summary>
        public string Time { get; set; }

        /// <summary>
        /// Gets or sets the date time.
        /// </summary>
        public DateTime DateTime
        {
            get
            {
                var date = DateTime.ParseExact(this.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                var time = DateTime.ParseExact(this.Time, "hh:mm", CultureInfo.InvariantCulture);

                return date.Add(time.TimeOfDay);
            }

            set
            {
                this.Date = value.ToString("yyyy-MM-dd");
                this.Time = value.ToString("hh:mm");
            }
        }

        /// <summary>
        /// Gets or sets the page.
        /// </summary>
        /// <remarks>
        /// 0 - 10. Allows pagination of connections. Zero-based, so first page is 0, second is 1, third is 2 and so on.
        /// </remarks>
        public int? Page { get; set; }

        /// <summary>
        /// Gets or sets the direct.
        /// </summary>
        /// <remarks>
        /// defaults to 0, if set to 1 only direct connections are allowed
        /// </remarks>
        public short Direct { get; set; }

        /// <summary>
        /// Gets or sets the sleeper.
        /// </summary>
        /// <remarks>
        /// defaults to 0, if set to 1 only night trains containing beds are allowed, implies direct=1
        /// </remarks>
        public short Sleeper { get; set; }

        /// <summary>
        /// Gets or sets the couchette.
        /// </summary>
        /// <remarks>
        /// defaults to 0, if set to 1 only night trains containing couchettes are allowed, implies direct=1
        /// </remarks>
        public short Couchette { get; set; }

        /// <summary>
        /// Gets or sets the bike.
        /// </summary>
        /// <remarks>
        /// defaults to 0, if set to 1 only trains allowing the transport of bicycles are allowed
        /// </remarks>
        public short Bike { get; set; }
    }
}
